class Solution:
    def minSwaps(self, s: str) -> int:
        c0, c1 = s.count("0"), s.count("1")
        if c0 + 1 < c1:
            return -1
        elif c0 + 1 == c1:
            ans = 0
            for i in range(0, len(s), 2):
                if s[i] != "1":
                    ans += 1
            return ans
        elif c0 == c1:
            ans1 = 0
            for i in range(0, len(s), 2):
                if s[i] == "0":
                    ans1 += 1
            ans2 = len(s) // 2 - ans1
            return min(ans1, ans2)
        elif c0 == c1 + 1:
            ans = 0
            for i in range(0, len(s), 2):
                if s[i] != "0":
                    ans += 1
            return ans
        else:  # c0 > c1 + 1
            return -1


if __name__ == "__main__":
    print(Solution().minSwaps("111000"))  # 1
    print(Solution().minSwaps("010"))  # 0
    print(Solution().minSwaps("1110"))  # -1

    print(Solution().minSwaps("1111000"))  # 2
    print(Solution().minSwaps("0000111"))  # 2
    print(Solution().minSwaps("000111"))  # 1
    print(Solution().minSwaps("0001"))  # -1
